
namespace Core.Features
{
    using System;
    using System.Linq;
    using Base;
    using Contracts.Enums;
    using Contracts.Interfaces;

    
    public sealed class MaximumTargets<T> : FeatureBase<object>
    {
        public MaximumTargets(){}

        public MaximumTargets(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Max targets"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.TargetingEquipment; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.MaximumTargets; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return "pcs"; } }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;

            var robotMaxTargets = (double)robot.Features.Where(f => f.FeatureType == this.FeatureType).First().Value;
            var extension = agent.Extensions.Where(e => e.GetType() == typeof (Extensions.Targeting)).FirstOrDefault();
            
            ModifiedValue = extension!=null 
                ?  extension.Level >= robotMaxTargets 
                    ? robotMaxTargets 
                    : extension.Level +1 
                : 1;
        }
    }
}